﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ataric.Themester.Parser;

namespace Ataric.Themester.Model
{
    public class SessionManager
    {
        public static CSSDocument WorkingDocument
        {
            get
            {
                if (UploadedCSSDocuments.Count > 0) return UploadedCSSDocuments[UploadedCSSDocuments.Count-1];
                return new CSSDocument();
              //  if (HttpContext.Current.Session["WorkingDocument"] == null) return new CSSDocument();
              //  return HttpContext.Current.Session["WorkingDocument"] as CSSDocument;
            }
            set {
                HttpContext.Current.Session["WorkingDocument"] = value;
            }

        }
        /// <summary>
        /// Return the list of css uploaded
        /// </summary>
        public static List<CSSDocument> UploadedCSSDocuments
        {
            get
            {
                if (HttpContext.Current.Session["UploadedCSSDocuments"] == null) return new List<CSSDocument>();
                return HttpContext.Current.Session["UploadedCSSDocuments"] as List<CSSDocument>;
            }
            set
            {
                HttpContext.Current.Session["UploadedCSSDocuments"] = value;
            }

        }


        public static CSSDocument ShareBrandInSession
        {
            get
            {
                return HttpContext.Current.Session["ShareBrandInSession"] as CSSDocument;
            }
            set
            {
                HttpContext.Current.Session["ShareBrandInSession"] = value;
            }
        }
        /// <summary>
        /// This is object model of sharepoint.css file put in app_data; 
        /// </summary>
        public static CSSDocument StaticSharepointCSSDocument
        {
            get
            {
                CSSDocument document = HttpContext.Current.Application["StaticSharepointCSSDocument"] as CSSDocument;
                if (document == null)
                {
                   CSSParser parser = new CSSParser();
                   document= parser.ParseFile(HttpContext.Current.Server.MapPath(Constants.SHAREPOINT_CSS_FILE_NAME));
                   HttpContext.Current.Application["StaticSharepointCSSDocument"] = document;
                }
                return document;
            }
            set
            {
                HttpContext.Current.Application["StaticSharepointCSSDocument"] = value;
            }

        }

    }
}